package com.four.hospital.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.common.utils.R;
import com.four.hospital.entity.Doctor;
import com.four.hospital.service.DoctorService;
import com.four.hospital.vo.DoctorAndUserVo;
import com.four.hospital.vo.DoctorVo;
import com.four.hospital.vo.DoctorVo3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:luojie
 * @Date: 2022/01/05/18:39
 * @Description
 */
@RestController
@RequestMapping("hospital/doctor")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    /**
     * 根据医院id，科室id，等级id查询医生信息
     *
     * @param hosId
     * @param depId
     * @param levId
     * @param vo
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/doctorList/{hosId}/{depId}/{levId}")
    public R doctorList(@PathVariable("hosId") Integer hosId,
                        @PathVariable("depId") Integer depId,
                        @PathVariable("levId") Integer levId,
                        @RequestBody DoctorVo vo,
                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "3") Integer size) {
        vo.setHosId(hosId);
        vo.setLevId(levId);
        vo.setDepId(depId);
        IPage<Doctor> doctorList = doctorService.doctorList(page, size, vo);
        return R.ok().put("doctorList", doctorList);
    }

    /**
     * 医生所看过的患者
     *
     * @param docId
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/doctorUder/{docId}")
    public R doctorUser(@PathVariable("docId") Integer docId,
                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "3") Integer size) {
        IPage<DoctorAndUserVo> doctorUser = doctorService.doctorUser(docId, page, size);
        return R.ok().put("doctorUser", doctorUser);
    }

    /**
     * 根据医生id回显到数据
     *
     * @param docId
     * @return
     */
    @GetMapping("/findById/{docId}")
    public Doctor findById(@PathVariable("docId") Integer docId) {

        return doctorService.findById(docId);
    }

    /**
     * 根据医生id来修改审核状态
     *
     * @param docId
     * @param doctor
     * @return
     */
    @PutMapping("/upDateDoctorById/{docId}")
    public R upDateDoctorById(@PathVariable("docId") Integer docId, @RequestBody Doctor doctor) {
        doctorService.upDateDoctorById(docId, doctor);
        return R.ok("修改成功");
    }

    /**
     * 快速问诊
     * 输入医生姓名查询信息
     *
     * @param dosName
     * @return
     */
    @GetMapping("/getDoctorByName/{dosName}")
    public R getDoctor(@PathVariable("dosName") String dosName) {
        List<Doctor> doctorList = doctorService.getDoctor(dosName);
        return R.ok().put("doctorList", doctorList);
    }

    /**
     * 选取科室，获取科室id
     * 根据科室id查询所有医生
     *
     * @param depId
     * @return
     */
    @GetMapping("/getDoctorByDepId/{depId}")
    public R getDoctorByDepId(@PathVariable("depId") Integer depId) {
        List<DoctorVo3> doctorList = doctorService.getDoctorByDepId(depId);
        return R.ok().put(" doctorList", doctorList);
    }

    /**
     * 根据选中的城市查询这个城市所有有的医生
     *
     * @param areaId
     * @return
     */
    @GetMapping("/getDoctorByAreaId/{areaId}")
    public R getDoctorByAreaId(@PathVariable("areaId") Integer areaId) {
        return doctorService.getDoctorByAreaId(areaId);
    }

    /**
     * 输入病症查询医生
     *
     * @param diseName
     * @return
     */
    @GetMapping("/getDoctorByDise/{diseName}")
    public R getDoctorByDise(@PathVariable("diseName") String diseName) {
        return doctorService.getDoctorByDise(diseName);
    }

    /**
     * 设置医生信息
     * @param docName
     * @param docPhone
     * @param docId
     * @return
     */
    @GetMapping("/updateDoctor/{docName}/{docPhone}/{docId}")
    public R updateDoctor(@PathVariable("docName") String docName,
                          @PathVariable("docPhone") String docPhone,
                          @PathVariable("docId") Integer docId) {
        return doctorService.updateDoctor(docName, docPhone, docId);
    }

    /**
     * 设置医生密码
     * @param oldPwd
     * @param newPwd
     * @param docId
     * @return
     */
    @GetMapping("updateDoctorPwd/{docId}/{oldPwd}/{newPwd}")
    public R updateDoctorPwd(@PathVariable("oldPwd") String oldPwd,
                             @PathVariable("newPwd") String newPwd,
                             @PathVariable("docId") Integer docId){
        return doctorService.updateDoctorPwd(oldPwd,newPwd,docId);
    }
}
